<!DOCTYPE html>
<html>
<head>
    <title>修改文档</title>
    <include file='public/head'>
	<style>
		.layui-legend-size{font-size:14px !important;}
		.layui-nopadding{padding:0 !important;}
		.layui-overflow{overflow:auto;}
		.layui-nomargin{margin: 0 !important;}
		.layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
		.layui-input{height:30px !important; }
		.layui-form-search-item .layui-inline{margin-bottom: 5px;} 
		.layui-form-search-item label{margin-left: 15px;}
		.layui-table-page {padding: 7px 0px 0px;}
		.layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
	</style>
</head>
<body>
<form class="layui-form" action="">
	<table class="layui-table layui-nomargin">
		<!-- 表格内容输出 -->
		<tbody>
			<tr>
				<td width="20%">文件名：</td>
				<td colspan="3"><input type="text" class="layui-input" name="file_name" id="file_name" placeholder="文件名" autocomplete="off" value="{$info.name}"></td>
			</tr>
			<tr>
				<td>上级目录：</td>
				<td colspan="3" style = "text-align:left">
			        <select name="modules" lay-filter="list" lay-verify="required" lay-search="" id="parent" name="parent" align="left">
			          <option value="">直接选择或搜索选择</option>
			          {$select}
			        </select>	
				</td>
			</tr>
			<tr>
				<td>是否私有：</td>	
				<td width="20%">
				    <div class="layui-input-block" class="layui-input-inline">
				      <input type="checkbox" class="layui-input-inline" id="switch" name="switch" lay-filter="change" lay-skin="switch" <php>if($info['private'] == "1"){echo "checked='checked'";}</php> >
				      <div id="tx" class="layui-input-inline"></div>
				    </div>				
				</td>	
				<td width="20%">
					指定人员查看:
				</td>
				<td>
					<div class="layui-input-inline" id="tshow" <php>if($info['private'] == "0"){echo "style='display: none;'";}</php>>
						<div id="users" name="users" class="layui-input-inline">
							<php> if(!empty($info['vid']['vname'])){echo $info['vid']['vname'];} </php>
						</div>
						<i class="layui-icon layui-icon-user layui-input-inline" style="font-size: 30px;" onclick="userList()"></i>
					</div>
				</td>
			</tr>
			<tr>
				<td colspan="4" height="500px">
					<script type="text/plain" id="edit" required style="height:500px;" name="edit" rows="12">{$info.content}</script>
				</td>
			</tr>
		</tbody>
	</table>
</form>	

<include file='public/scripts'>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>

<script type="text/javascript">

document.onkeydown = function( e ) {
	if (e.ctrlKey && e.which == 83) {
		e.preventDefault();
		return false;
	}
}


	var ue = UE.getEditor('edit' , { zIndex: 100});
	UE.getEditor('edit').addListener( 'keydown' , function(edit,oEvent){
		  var oEvent = oEvent || window.oEvent; 
		  //获取键盘的keyCode值
		  var nKeyCode = oEvent.keyCode || oEvent.which || oEvent.charCode;

		  //do something
		  if(nKeyCode == 83 && (oEvent.ctrlKey||oEvent.metaKey)){
				parent.$('.layui-layer-btn0').click();
	
				oEvent.preventDefault();
				return false;
			}
	});
	

	// layui.use('layedit', function(){
	  // var layedit = layui.layedit;
	  // var edit = layedit.build('edit',{
	  // 	height : '500'
	  // }); //建立编辑器
	// });	

    var form = layui.form;
	  
	form.on('select(list)', function(data){
        let selectText=data.elem[data.elem.selectedIndex].text;//得到被选中的文本值
        // selectText=selectText.trim();//去掉&nbap
        selectText=selectText.replace(/\s+/g, "");
        data.elem[data.elem.selectedIndex].text=selectText;//覆盖原文本值
        checkParent();
    });	

    form.on('switch(change)',function(){
		$('#tshow').toggle();
		if(private == 0){
			private = 1;
		}else if(private == 1){
			private = 0;
		}
    });

    //加载时检测
    checkParent();

    //检查父类
    function checkParent(){
		let data = {};
		data['id'] = $('#parent').val();
		if(data['id']){
			$.ajax({
				url:"{:cmf_plugin_url('Word://admin_index/checkParent')}",
				data:data,
				type:"post",
				//得到选中的内容
				success:function(data){
					//父级私有
					if(data == 1){
						$('#switch').prop('checked','true');
						$('#switch').prop('disabled','true');
						$('#tshow').show();
						$('#tx').html('当前目录不可公开');
						private = 1;
					//父级公开
					}else{
						$('#switch').removeAttr('checked');
						$('#switch').removeAttr('disabled');
						$('#tshow').hide();
						$('#tx').html('');
						private = 0;
					}
					form.render();
				},
				error:function(data){
					layer.msg('查询失败');
					return false;
				}
			})		
		}
    }   


	//获取选择值
	function callbackdata(){
		var content = {};
		if($('#file_name').val() == ''){
			layer.msg('请输入文件名');
			return false;
		}
		if(ue.getContent() == ''){
			layer.msg('请输入文章内容');
			return false;
		}
		content['id'] = {$info.id};
		// content['content'] = layedit.getContent(edit);
		content['content'] = ue.getContent();
		content['name'] = $('#file_name').val();
		content['parent_id'] = $('#parent').val();
		content['vid'] = vid;
		content['private'] = private;
		return content;
	}

	var vname = [];
	var vid = [{$info.vid.vid}];
	var private = {$info.private};
	//用户列表
	function userList(){
			let url = "{:cmf_plugin_url('Word://admin_index/userList')}?&vid="+vid;
			layer.open({
				type: 2//基本层类型  0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
				,title: '用户列表'//层的标题
				,shadeClose: true//是否点击遮罩关闭
				,shade: 0.8//遮罩
				,area: ['500px', '500px']//宽高
				,btn:['提交','关闭']//弹框按钮
				,fixed:false//固定
				,content: url //iframe的url
				,yes:function(index, layero){
					//调用子页面方法得到返回值
					parentInfo = window["layui-layer-iframe" + index].callbackdata(index);
					vname = parentInfo['vname'];
					vid = parentInfo['vid'];
					$('#users').html(vname.join(','));
					layer.closeAll();
					if(parentInfo == false){
						return false;
					}
				}
				,btn2:function(index, layero){
				}
			});
	}
	



</script>
</body>
</html>